# encoding: utf-8

class Member < ActiveRecord::Base
  belongs_to  :project,
              :touch  =>  true

  belongs_to  :user

  # Validations
  validates :user_id,
            :presence     =>  true,
            :numericality =>  { :only_integer =>  true,
                                :greater_than =>  0  }

  validates :project_id,
            :presence     =>  true,
            :numericality =>  { :only_integer =>  true,
                                :greater_than =>  0  }

  validates :role,
            :presence   =>  true,
            :inclusion  =>  { :in =>  ['manager', 'employee'] }

	validates :load,
            :presence     =>  true,
            :numericality =>  { :only_integer =>  true,
                                :greater_than_or_equal_to =>  1, :unless => "self.load.blank?" }

  validates :status,
            :presence   =>  true,
            :inclusion  =>  { :in =>  ['available', 'on_vacation', 'sick', 'busy', 'in_training'] }
end


# == Schema Information
#
# Table name: members
#
#  id         :integer         not null, primary key
#  project_id :integer
#  user_id    :integer
#  role       :string(255)
#  load       :integer         default(0)
#  status     :string(255)     default("available")
#  created_at :datetime
#  updated_at :datetime
#

